package butines.kraz.entity;

import butines.core.GameSystem;
import butines.core.math.Vector2f;

public class PathPlanning {

	private Unit owner;
	
	private Vector2f start;
	private Vector2f end;
	
	private float expectedTime;
	private float countdown;
	
	public PathPlanning(Unit owner) {
		this.owner = owner;
	}
	
	public void calcule() {
		start = owner.getPosition().copy();
		end = owner.getTarget().copy();
		expectedTime = (Vector2f.distance(start,end) / (owner.getMaxSpeed() * GameSystem.getTargetFps())) + 2;
		countdown = expectedTime;
	}

	public Vector2f getStart() {
		return start;
	}

	public Vector2f getEnd() {
		return end;
	}

	public float getExpectedTime() {
		return expectedTime;
	}
	
	public boolean isTimeout() {
		return countdown <= 0;
	}
	
	public void update(float tpf) {
		if (countdown > 0) {
			countdown -= tpf;
		}
	}
	
}
